package com.yungu.swift.order.utils;

import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.order.model.dto.OrderDetailDto;
import com.yungu.swift.order.model.dto.OrderDto;
import com.yungu.swift.order.model.param.CrosstownAssignOrderParam;
import com.yungu.swift.socket.push.model.PushContent;
import com.yungu.swift.utils.MapUtils;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * 消息推送处理
 */
public class PushContentUtils {

    /**
     * 跨城司机派单通知
     */
    public static PushContent crosstownAssignToDriver(CrosstownAssignOrderParam crosstownAssignOrderParam) {
        Map<String, Object> data = MapUtils.build();
        OrderDto orderDto = crosstownAssignOrderParam.getCurrentOrderDto();
        OrderDetailDto orderDetailDto = crosstownAssignOrderParam.getCurrentOrderDetailDto();
        data.put("orderUuid", orderDto.getUuid());
        data.put("title", "派单成功");
        data.put("moduleType", orderDto.getTypeModule());
        StringBuilder content = new StringBuilder();

        if (orderDto.getTypeJoin() == CommonConstant.ORDER_TYPE_JOIN_ORDINARY) {
            content.append("拼车,");
        } else if (orderDto.getTypeJoin() == CommonConstant.ORDER_TYPE_JOIN_CHARTERED) {
            content.append("包车,");
        } else {
            content.append("寄件,");
        }
        content.append(CommonUtils.getTimeTodayOrTomorrow(new Timestamp(orderDetailDto.getDeparTime().getTime())));
        content.append("从").append(orderDetailDto.getOriginAddress()).append("到").append(orderDetailDto.getDestAddress());
        content.append("请及时处理订单");

        data.put("content", content.toString());
        data.put("report", content.toString());
        return PushContent.newInstance4Dri(orderDto.getAppid(), PushContent.ORDER_JOIN_DRI_ASSIGNED, data);
    }

    /**
     * 跨城派单成功通知乘客
     */
    public static PushContent crosstownAssignToPassener(String orderUuid, Integer typeModule, String appid) {
        Map<String, Object> data = MapUtils.build();
        data.put("orderUuid", orderUuid);
        data.put("title", "派单成功");
        data.put("moduleType", typeModule);
        String msg = "您的订单已指派到司机！";
        data.put("content", msg);
        data.put("report", msg);
        return PushContent.newInstance4Dri(appid, PushContent.ORDER_JOIN_PAS_ASSIGNED, data);
    }

    /**
     * 跨城改派通知原司机
     */
    public static PushContent crosstowChangeAssignToCurDriver(CrosstownAssignOrderParam crosstownAssignOrderParam) {
        Map<String, Object> data = MapUtils.build();
        data.put("orderUuid", crosstownAssignOrderParam.getCurrentOrderUuid());
        data.put("title", "订单改派通知");
        data.put("content", "您有一个订单已被改派给其他司机，请注意行程变化");
        data.put("moduleType", crosstownAssignOrderParam.getCurrentOrderDto().getTypeModule());
        return PushContent.newInstance4Dri(crosstownAssignOrderParam.getCurrentOrderDto().getAppid(), PushContent.ORDER_JOIN_DRI_OLD_CHANGE_ASSIGNED, data);
    }

    /**
     * 跨城改派通知新司机
     */
    public static PushContent crosstowChangeAssignToNewDriver(CrosstownAssignOrderParam crosstownAssignOrderParam) {
        Map<String, Object> data = MapUtils.build();
        data.put("orderUuid", crosstownAssignOrderParam.getCurrentOrderUuid());
        data.put("title", "订单改派通知");
        data.put("moduleType", crosstownAssignOrderParam.getCurrentOrderDto().getTypeModule());
        data.put("content", "收到一个订单改派，请注意查看订单详情");
        return PushContent.newInstance4Dri(crosstownAssignOrderParam.getCurrentOrderDto().getAppid(), PushContent.ORDER_JOIN_DRI_NEW_CHANGE_ASSIGNED, data);
    }

    /**
     * 跨城改派通知乘客
     */
    public static PushContent crosstowChangeAssignToNewPassemger(CrosstownAssignOrderParam crosstownAssignOrderParam) {
        Map<String, Object> data = MapUtils.build();
        data.put("orderUuid", crosstownAssignOrderParam.getCurrentOrderUuid());
        data.put("title", "订单改派通知");
        data.put("content", "您的订单因特殊原因，已被改派给其他司机，行程将继续进行，请耐心等候");
        data.put("moduleType", crosstownAssignOrderParam.getCurrentOrderDto().getTypeModule());
        return PushContent.newInstance4Pas(crosstownAssignOrderParam.getCurrentOrderDto().getAppid(), PushContent.ORDER_JOIN_PAS_CHANGE_ASSIGNED, data);
    }

    /**
     * 跨城合并派单司机通知
     */
    public static PushContent crosstownMargeAssignToDriver(String mainOrderUuid,List<String> orderUuidList, String appid) {
        Map<String, Object> data = MapUtils.build();
        data.put("mainOrderUuid",mainOrderUuid);
        data.put("orderUuidList", orderUuidList);
        data.put("title", "收到派单");
        StringBuilder content = new StringBuilder();
        content.append("收到系统指派的").append(orderUuidList.size()).append("笔订单");
        content.append("，请及时处理订单");
        data.put("content", content.toString());
        data.put("report", content.toString());
        return PushContent.newInstance4Dri(appid, PushContent.ORDER_JOIN_DRI_NEW_MARGE_ASSIGNED, data);
    }

}
